import {
    getDoorList,
    // getCompanyId,
    getAxis,
    getPie,
    getPass,
    getRead,
    getApprove
} from '@/services/gateway';
// import { call } from 'redux-saga/effects';

export default {
    namespace: 'gateway',
    state: {
        data: {
            noticeCount: 0,
            ruleCount: 0,
            ruleList: [],
            noticeList: []
        },
        newsList: [
            {
                companyId: '4',
                content: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                createUser: 'wnan',
                id: '15',
                recvCompany: 'xmWWww',
                title: '公司新闻-111',
                topFlag: 1,
                updateUser: 'wunannan',
                status: 1,
                time: '2018-10-10 12:20:30',
                deleteFlag: 0
            },
            {
                companyId: '5',
                content: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                createUser: 'wunan',
                id: '25',
                recvCompany: 'xmWW',
                title: '公司新闻-222',
                topFlag: 1,
                updateUser: 'wunan',
                status: 1,
                time: '2018-10-10 12:20:30',
                deleteFlag: 0
            }
        ],
        pieData: [],
        option3data: [],
        colorChoose: '#3BA0FF',
        chooseIndex: '',
        pieColor: [
            '#3BA0FF',
            '#FAD337',
            '#F2637B',
            '#36CBCB',
            '#FFA22D',
            '#4ECB74',
            '#975FE4',
            '#FFBCD9',
            '#CB6137',
            '#FFF148',
            '#49E3AC',
            '#FF7800',
            '#9290FF',
            '#3EEDE7',
            '#FF51A7',
            '#698BFF',
            '#FAFF72'
        ],
        threeApp: [
            {
                name: '微微官网',
                url: 'http://www.vv.cn/'
            },
            { name: 'WIKI', url: 'http://wiki.vv.cn:8090/#all-updates' },
            {
                name: 'JIRA',
                url: 'http://172.16.1.122:8000/secure/Dashboard.jspa'
            },
            {
                name: '钉钉',
                url:
                    'https://oa.dingtalk.com/?spm=a3140.8736650.2231602.14.7f1518e6NfCSlY#/login'
            },
            {
                name: '智联招聘',
                url:
                    'http://landing.zhaopin.com/register?utm_source=baidupcpz&utm_medium=cpt&utm_provider=partner&sid=121113803&site=null'
            },
            {
                name: '蓝湖',
                url: 'https://lanhuapp.com/web/#/item'
            }
        ],
        chooseDate: '',
        chooseWeek: '',
        axisData: {
            list: []
        },
        passData: [],
        readData: [],
        approveData: [],
        passDataCount: 0,
        readDataCount: 0,
        approveCount: 0
    },
    effects: {
        *fetchList({ payload }, { call, put }) {
            const result = yield call(getDoorList, payload);
            if (result.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        data: result.data
                    }
                });
            }
        },
        // 经我审批流程列表
        // eslint-disable-next-line no-empty-function
        *getWorkData({ payload }, { put, call, all }) {
            const [fetchApproveList, fetchPassList, fetchReadList] = yield all([
                call(getApprove, payload),
                call(getPass, payload),
                call(getRead, { ...payload, readStatus: 0 })
            ]);
            // 待我审批列表
            if (fetchApproveList.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        approveData: fetchApproveList.data.rows,
                        approveCount: fetchApproveList.data.total
                    }
                });
            }
            // 待我阅读列表
            if (fetchReadList.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        readData: fetchReadList.data.rows,
                        readDataCount: fetchReadList.data.total
                    }
                });
            }
            // 经我审批流程列表
            if (fetchPassList.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        passData: fetchPassList.data.rows,
                        passDataCount: fetchPassList.data.total
                    }
                });
            }
        },

        // 获取柱状图数据
        *fetchAxis({ payload }, { put, call }) {
            const result = yield call(getAxis, payload);
            if (result && result.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        axisData: result.data
                    }
                });
            }
        },
        // 获取饼图数据
        *fetchPie({ payload }, { put, call }) {
            const result = yield call(getPie, payload);
            if (result.code === 10000) {
                yield put({
                    type: 'saveCharts',
                    payload: {
                        pieData: result.data
                    }
                });
                if (result.data.length > 0 && result.data[0].children) {
                    yield put({
                        type: 'getNewOption',
                        payload: {
                            option3data: result.data[0].children,
                            chooseIndex: result.data[0].name
                        }
                    });
                }
            }
        }
    },
    reducers: {
        getNewOption(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        },
        chooseNewdate(state, action) {
            return {
                ...state,
                ...action.payload
            };
        },
        saveCharts(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
